<template>
    <div class="applyList preApproveManage">
        <rui-page :defines="defines" :has-card-box="false" class="preApprove">
            <!-- 查询条件 -->
            <rui-query ref="preApproveForm"
                       :label-width="100"
                       isApplyQuery
                       :query="queryData"
                       :query-rows="searchFormOptions"
                       :more-rows="moreSearchFormOptions">
            </rui-query>
            <div class="table-card">
                <div class="btn-status flex flex-between">
                    <div class="loanApplyBtn">
                        <Button class="btn" type="primary" v-if="$store.getters.permissions['apply-pre-approved']"  @click.native="add()"
                                size="default">新增
                        </Button>
                        <Button class="btn" @click.native="refresh()" size="default">刷新</Button>
                    </div>
                </div>
                <rui-table
                    :defineId="'preApproveManageJS'"
                    :fixedRight="['action']"
                    :showIndex="false"
                    :select="false"
                    :columns="preApproveColumns"
                    :slots="[{key:'action',slot:'action'},{key:'createBy',slot:'createBy'}]"
                    @loadDatas="queryData"
                    :border="false"
                    ref-query="preApproveForm"
                    ref="preApproveTable"
                >
                    <template slot-scope="{ row,  index, }" slot="createBy">
                        <Badge>{{row.sellerRealName}}({{row.createBy}})</Badge>
                    </template>
                    <!--实现操作选项显示方式：下拉菜单-->
                    <div class="btn-no-border" slot="action" slot-scope="{ row }">
                        <template v-if="(row.applyStatus==='4'||row.applyStatus==='0')&&username!='admin'">
                            <Button ghost v-if="$store.getters.permissions['apply-pre-approved_edit']"  type="primary" @click.native="edit(row)">编辑
                            </Button>
                        </template>
                        <template v-if="row.applyStatus==='0'&&username!='admin'">
                            <Button ghost v-if="$store.getters.permissions['apply-pre-approved_del']"  type="primary" @click.native="remove(row)">删除
                            </Button>
                        </template>
                        <template
                            v-if="(row.applyStatus==='1'||row.applyStatus==='A'||row.applyStatus==='B'||row.applyStatus==='C'||row.applyStatus==='D')&&username!=='admin'">
                            <Button ghost v-if="$store.getters.permissions['apply-pre-approved_add']"  type="primary" @click.native="startApprove(row)">
                                申请进件
                            </Button>
                        </template>
                    </div>
                </rui-table>
            </div>
            <!--新增-->
            <Modal v-model="addPreApproveModalVisible"
                   :title="addPreApproveTitle"
                   :width="1100"
                   :mask-closable="false"
                   :on-change="changeButton()"
                   @on-ok="submit">
                <div class="preApproveFormOptionsForm">
                    <Form ref="addPreApproveForm" :model="addPreApproveForm" :rules="formRule" :label-width="120">
                        <Row>
                            <Col span="12">
                                <FormItem label="业务类型:" prop="businessType">
                                    <Select v-model="addPreApproveForm.businessType" clearable>
                                        <Option value="01" :disabled="isNewCarDisabled">新车</Option>
                                        <Option value="02" :disabled="isOldCarDisabled">二手车</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="12">
                                <FormItem label="手机号码:" prop="telPhone">
                                    <Input v-model="addPreApproveForm.telPhone" maxlength="11" clearable/>
                                </FormItem>
                            </Col>
                            <Col span="12">
                                <FormItem label="客户姓名:" prop="custName">
                                    <Input v-model="addPreApproveForm.custName" clearable/>
                                </FormItem>
                            </Col>
                            <Col span="12">
                                <FormItem :rules="addPreApproveForm.isLongTerm?clearCertEndDate:requeirCertEndDate"
                                          label="身份证到期日:" prop="certEndDate">
                                    <DatePicker type="date" v-model="addPreApproveForm.certEndDate"
                                                :disabled="addPreApproveForm.isLongTerm"></DatePicker>
                                </FormItem>
                                <FormItem label prop="isLongTerm" :label-width="10"
                                          style="position: absolute;width:80px;left:320px;top:0">
                                    <Checkbox v-model="addPreApproveForm.isLongTerm"
                                              @on-change="selectCheckBox">长期
                                    </Checkbox>
                                </FormItem>
                            </Col>
                            <Col span="12">
                                <FormItem label="证件号码:" prop="certNo">
                                    <Input v-model="addPreApproveForm.certNo" maxlength="18" clearable/>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row class="preApproveUpload">
                            <div class="uploadInfo pr">
                                <label>影像信息:</label>
                                <card-upload ref="addcarUpload" :frontType="preFrontType"
                                             :balckType="preBlackType"
                                             @queryZmInfo="queryZmInfo"
                                             @queryFmInfo="queryFmInfo"
                                ></card-upload>
                            </div>
                        </Row>
                    </Form>
                </div>
                <!--二维码展示-->
                <div style="text-align: center" v-if="binary">
                    <img id="qrcode" :src="'data:image/jpg;base64,'+binary">
                    <p style="font-size: 13px;">
                        <Icon type="ios-alert" color="red">
                        </Icon>&nbsp;请扫描二维码进行认证（有效时间:30分钟）
                    </p>
                </div>
                <div slot="footer">
                    <!--暂存：成功返回二维码 -->
                    <Button type="primary" :disabled="disabled" @click="refreshQrCode()" v-if="binary">
                        {{codeName}}
                    </Button>
                    <Button size="small" type="success" icon="ios-folder-open-outline" @click.native="storeInfo">保存
                    </Button>
                    <Button size="small" type="info" @click.native="turnBack()"
                            icon="ios-backspace-outline">返回
                    </Button>
                    <!--新增：成功返回二维码 -->
                    <Button type="primary" size="small" @click.native="submit" icon="ios-bookmark"
                            :disabled="this.showButton">提交
                    </Button>
                </div>
            </Modal>
            <!--编辑弹窗-->
            <Modal v-model="editPreApproveModalVisible"
                   :title="editPreApproveTitle"
                   :width="1100"
                   :mask-closable="false"
                   @on-ok="submit">
                <div class="preApproveFormOptionsForm">
                    <Form ref="editPreApproveForm" :model="editPreApproveForm" :rules="formRule" :label-width="120">
                        <Row>
                            <Col span="12">
                                <FormItem label="业务类型:" prop="businessType">
                                    <Select v-model="editPreApproveForm.businessType" clearable>
                                        <Option value="01" :disabled="isNewCarDisabled">新车</Option>
                                        <Option value="02" :disabled="isOldCarDisabled">二手车</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="12">
                                <FormItem label="手机号码:" prop="telPhone">
                                    <Input v-model="editPreApproveForm.telPhone" maxlength="11" clearable/>
                                </FormItem>
                            </Col>
                            <Col span="12">
                                <FormItem label="客户姓名:" prop="custName">
                                    <Input v-model="editPreApproveForm.custName" clearable/>
                                </FormItem>
                            </Col>
                            <Col span="12">
                                <FormItem :rules="editPreApproveForm.isLongTerm?clearCertEndDate:requeirCertEndDate"
                                          label="身份证到期日:" prop="certEndDate">
                                    <DatePicker type="date" v-model="editPreApproveForm.certEndDate"
                                                :disabled="editPreApproveForm.isLongTerm"></DatePicker>
                                </FormItem>
                                <FormItem label prop="isLongTerm" :label-width="10"
                                          style="position: absolute;width:80px;left:320px;top:0">
                                    <Checkbox v-model="editPreApproveForm.isLongTerm"
                                              @on-change="selectCheckBox">长期
                                    </Checkbox>
                                </FormItem>
                            </Col>
                            <Col span="12">
                                <FormItem label="证件号码:" prop="certNo">
                                    <Input v-model="editPreApproveForm.certNo" maxlength="18" clearable/>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row class="preApproveUpload">
                            <div class="uploadInfo pr editPreApprove">
                                <label>影像信息:</label>
                                <card-upload ref="editcarUpload" :frontType="preFrontType" :balckType="preBlackType"
                                             @queryZmInfo="queryZmInfo"
                                             @queryFmInfo="queryFmInfo"
                                ></card-upload>
                            </div>
                        </Row>
                    </Form>
                </div>
                <!--二维码展示-->
                <div style="text-align: center" v-if="binary">
                    <img id="rcode" :src="'data:image/PNG;base64,'+binary">
                    <p style="font-size: 13px;">
                        <Icon type="ios-alert" color="red">
                        </Icon>&nbsp;请扫描二维码进行认证（有效时间:30分钟）
                    </p>
                </div>
                <div slot="footer">
                    <Button type="info" :disabled="disabled" v-if="binary"
                            @click="refreshQrCode()">{{codeName}}
                    </Button>
                    <Button size="small" type="info" @click="editTurnBack()"
                            icon="ios-backspace-outline">返回
                    </Button>
                    <Button type="primary" size="small" @click="submit" icon="ios-bookmark">提交</Button>
                </div>
            </Modal>
            <!--详情-->
            <Modal v-model="detailsModalVisible"
                   :title="detailsPreApproveTitle"
                   :width="1100"
                   :mask-closable="false">
                <rui-form :form-options="detailsPreApproveFormOptions"
                          ref="detailsPreApproveForm">
                </rui-form>
                <div style="padding-left: 77px;"
                     v-if="this.fileServiceOne!==null">
                    征信授权书:&nbsp;&nbsp;《{{this.fileName}}》
                    <Button @click.native="showFileServiceOne">预览</Button>&nbsp;&nbsp;
                    <Button @click.native="downloadFileServiceOne">下载</Button>
                </div>
                <div class="uploadInfo pr editPreApprove">
                    <label>影像信息:</label>
                    <card-upload ref="detailsCarUpload" :frontType="preFrontType" :isDeatils="isDeatils"
                                 :balckType="preBlackType"></card-upload>
                </div>
                <div slot="footer">
                    <Button size="small" type="info" @click="detailsModalVisible = false"
                            icon="ios-backspace-outline">返回
                    </Button>
                </div>
            </Modal>
        </rui-page>
    </div>
</template>
<script>
    import preApproveManageJS from "../../api/pre-approve/preApproveManage";
    import {
        deletePreApprove,
        edit,
        getListData,
        getToken,
        preApproveMessageSender,
        refresh,
        save,
        store,
    } from "../../api/pre-approve/preApproveManage-form-api";
    import {deepClone} from "../../../../libs/utils/ObjectClone";
    import {getUserInfo} from "@/projects/basic/api/admin/user";
    import {doValidID, isNameValiate, isPhoneValiate} from '_p/afs-apply/assets/js/utils.js'
    import utils from "@/libs/util.js";
    import CardUpload from "@/components/identitycard-upload"
    import {downloadSingleFile} from "../../api/contract/corporate/corporateTransferManagement";

    export default {
        mounted() {
            // this.getToken();
            this.refresh();
            window.preApproveDetails = this.preApproveDetails;
            this.setCurrentUserBusinessType("addPreApproveForm");
            this.setCurrentUserBusinessType();
        },
        data() {
            return {
                isDeatils: false,
                preRow: "",
                preFrontType: "preborroweridcardfront",
                preBlackType: "preBorrowerIdcardBack",
                id: "",
                fileId: '',
                md5: '',
                fileName: '',
                path: "apply",
                fileServiceOne: {},
                tempBusiNo: "",
                channelBelong: "",
                deptIds: {},
                deptId: "",
                channelFullName: "",
                channelId: 0,
                sellerPhone: "",
                sellerRealName: "",
                time: null,
                countDown: '',
                showButton: false,
                codeName: "",
                username: '',
                refreshTime: '',
                disabled: false,
                blackData: [],
                binary: '',
                addPreApproveTitle: '新增',
                editPreApproveTitle: '编辑',
                detailsPreApproveTitle: '详情',
                editPreApproveModalVisible: false,
                addPreApproveModalVisible: false,
                detailsModalVisible: false,
                //查询
                searchFormOptions: [
                    {
                        isGroup: false,
                        defineId: "preApproveManageJS",
                        // fields: ["custName", "applyTime", "telPhone",],
                        fields: ["key"],
                    },
                ],
                moreSearchFormOptions: [
                    {
                        isGroup: false,
                        defineId: "preApproveManageJS",
                        fields: ["custName", "applyTime", "telPhone", "certNo", "applyStatus"],
                    },
                ],
                //显示
                preApproveColumns: [
                    'applyNo', 'custName', 'businessType', 'applyStatus', 'certNo', 'telPhone', "applyDate", "approveDate", 'certEndDate', 'createBy', 'action'
                ],
                addPreApproveForm: {
                    businessType: "",
                    telPhone: "",
                    custName: "",
                    certEndDate: "",
                    certNo: "",
                    isLongTerm: false,
                },
                editPreApproveForm: {
                    businessType: "",
                    telPhone: "",
                    custName: "",
                    certEndDate: "",
                    certNo: "",
                    isLongTerm: false,
                },
                //编辑
                // editPreApproveFormOptions: [
                //     {
                //         isGroup: false,
                //         groupName: '预审批编辑',
                //         grids: [
                //             {
                //                 defineId: "preApproveManageJS",
                //                 span: 8,
                //                 fields: ["businessType", "custName", "certNo",],
                //                 slots: [{key: 'businessType', slotName: 'businessType'}]
                //             },
                //             {defineId: "preApproveManageJS", span: 8, fields: ["telPhone", "certEndDate",]},
                //             {defineId: "preApproveManageJS", span: 8, fields: ["isLongTerm",]},
                //         ]
                //     }
                // ],
                //详情
                detailsPreApproveFormOptions: [
                    {
                        isGroup: false,
                        groupName: '预审批详情',
                        grids: [
                            {
                                defineId: "preApproveManageJS",
                                span: 6,
                                fields: ["businessType", "custName", "certNo", "threeCaResult",]
                            },
                            {
                                defineId: "preApproveManageJS",
                                span: 6,
                                fields: ['applyStatus', "telPhone", "applyDate", "faceResult",]
                            },
                            {
                                defineId: "preApproveManageJS",
                                span: 6,
                                fields: ["certEndDate", "approveDate", 'createBy', 'signResult',]
                            }, {
                                defineId: "preApproveManageJS",
                                span: 6,
                                fields: ["isLongTerm"]
                            },
                        ]
                    }
                ],
                isNewCarDisabled: true,
                isOldCarDisabled: true,
                // 单独对证件到期日校验
                requeirCertEndDate: [
                    {required: true, message: "证件到期日不能为空", trigger: "change", type: 'date'}
                ],
                clearCertEndDate: [{required: false}],
                formRule: {
                    businessType: [
                        {required: true, message: "请至少选择一项", trigger: "change"}
                    ],
                    telPhone: [
                        {required: true, message: "手机号码值不能为空", trigger: "change"},
                        {validator: isPhoneValiate, trigger: "change"}
                    ],
                    custName: [
                        {required: true, message: "客户姓名值不能为空", trigger: "change"},
                        {validator: isNameValiate, trigger: "change"}
                    ],
                    // certEndDate: [
                    //     {required: true, type: 'date', message: "身份证到期日值不能为空", trigger: "change"}
                    // ],
                    certNo: [
                        {required: true, message: "证件号码值不能为空", trigger: "change"},
                        {validator: doValidID, trigger: "change"}
                    ]
                }
            };
        },
        components: {
            CardUpload,
        },
        methods: {
            //长期
            selectCheckBox(value) {
                if (value === true) {
                    this.addPreApproveForm.certEndDate = "";
                    this.editPreApproveForm.certEndDate = "";
                } else {
                    this.addPreApproveForm.isLongTerm = false;
                }
            },
            //预览征信授权书
            showFileServiceOne() {
                let pdfurl = `${_AFS_PROJECT_CONFIG.apiUri}/${this.path}/upload/getBlob/pdf/${this.md5}`;
                window.open(pdfurl);
            },
            //下载征信授权书
            downloadFileServiceOne() {
                console.log("下载:", this.fileId);
                let params = {
                    id: this.fileId
                }
                let self = this;
                downloadSingleFile(params).then(function (response) {
                    if (response.status === 200) {
                        self.afs.downloadFile(response);
                    }
                })
            },
            queryZmInfo(data) {
                if (data) {
                    if (this.addPreApproveModalVisible) {
                        this.addPreApproveForm.custName = data.name;
                        this.addPreApproveForm.certNo = data.number;
                    } else if (this.editPreApproveModalVisible) {
                        this.preRow.custName = data.name;
                        this.preRow.certNo = data.number;
                        this.$refs.editPreApproveForm.updateFormData(this.preRow);
                    }

                }
            },
            queryFmInfo(data) {
                if (data) {
                    if (this.addPreApproveModalVisible) {
                        this.addPreApproveForm.certEndDate = data.validUntil;
                    } else if (this.editPreApproveModalVisible) {
                        this.preRow.certEndDate = data.validUntil;
                        this.$refs.editPreApproveForm.updateFormData(this.preRow);
                    }
                }
            },
            getToken() {
                getToken().then(res => {
                    if (res.code === '0000') {
                        this.$Message(res.data);
                    }
                });
            },
            destroyed() {
                // 清除定时器
                clearInterval(this.countDown)
                this.countDown = null;
            },
            //数据完整时，按钮显示
            changeButton() {
                this.showButton = false;
            },
            //刷新二维码信息,并更新数据
            refreshQrCode() {
                let v = {};
                this.countDown = setInterval(() => {
                    //如果刷新时间为空，那么就可以点击刷新
                    if (this.refreshTime === '') {
                        this.disabled = false;
                        this.codeName = "刷新二维码";
                        this.binary = '';
                        v = {
                            id: this.id
                        }
                        //点击刷新
                        refresh(v).then(res => {
                            if (res.code === '0000') {
                                this.$Message.success("刷新成功");
                                this.refreshTime = res.data.activeTime;
                                this.binary = res.data.code;
                            }
                        })
                    } else {
                        this.disabled = true;
                        this.codeName = this.refreshTime-- + 's后再次刷新';
                        console.log(this.codeName, "codeName")
                    }
                }, 1800);
            },
            //详情
            preApproveDetails(row) {
                this.modalType = 1;
                this.modalTitle = "预审批详情";
                this.$refs.detailsPreApproveForm.resetFrom();
                this.$refs.detailsPreApproveForm.updateFormData(deepClone(row));
                this.$refs.detailsPreApproveForm.setAllFieldReadOnly(true);
                this.detailsModalVisible = true;
                this.isDeatils = true;
                if (row.fileServiceOne != undefined) {
                    this.fileServiceOne = row.fileServiceOne;
                    this.fileName = row.fileServiceOne.fileName;
                    this.fileId = row.fileServiceOne.id;
                    this.md5 = row.fileServiceOne.fileId;
                } else {
                    this.fileServiceOne = null;
                }
                let self = this;
                this.$nextTick(function () {
                    self.$refs.detailsCarUpload.resetimgurl();
                    self.$refs.detailsCarUpload.showCarImg(row.id);
                })
            },
            //发起进件申请
            startApprove(row) {
                let param = {
                    preId: row.id,
                    signResult: row.signResult,
                    data: row,
                    diffType: "preApprove",
                };
                this.afs.newTab(this, 'projects/afs-apply/pages/apply-report/personal/index', '进件申请', 'ios-bookmark',
                    param, 'index' + param.preId, [], true);
            },
            turnBack() {
                this.addPreApproveModalVisible = false;
                this.binary = '';
                this.destroyed();
            },
            editTurnBack() {
                this.editPreApproveModalVisible = false;
                this.binary = '';
                this.destroyed();
            },
            //查询方法
            queryData(queryData) {
                if (typeof queryData.condition.applyTime != "undefined") {
                    queryData.condition.startDate = queryData.condition.applyTime[0];
                    queryData.condition.endDate = queryData.condition.applyTime[1];
                }
                getListData(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.blackData = res.data.records;
                        if (res.data.records.isLongTerm == '1' && res.data.records.isLongTerm != undefined) {
                            console.log("i你来了")
                            this.addPreApproveForm.certEndDate = '';
                        } else {
                            console.log("你来了")
                            this.addPreApproveForm.certEndDate = res.data.records.certEndDate;
                        }
                        this.$refs.preApproveTable.updateTableData(records, total);
                    }
                });
            },
            //刷新
            refresh() {
                this.$refs['preApproveTable'].reloadData();
            },
            //弹出新增窗口
            add() {
                this.modalType = 0;
                this.refreshTime = '';
                this.binary = '';
                this.addPreApproveTitle = "新增预审批";
                this.$refs.addPreApproveForm.resetFields();
                this.addPreApproveModalVisible = true;
                let self = this;
                this.$nextTick(function () {
                    self.$refs.addcarUpload.resetimgurl();
                })
            },
            //弹出编辑窗口
            edit(row) {
                console.log(row);
                this.modalType = 1;
                this.refreshTime = '';
                this.binary = '';
                this.modalTitle = "预审批修改";
                this.$refs.editPreApproveForm.resetFields();
                this.preRow = deepClone(row);
                this.editPreApproveForm = deepClone(row);
                console.log(this.editPreApproveForm);
                if (row.isLongTerm == '1') {
                    this.editPreApproveForm.isLongTerm = true;
                    this.editPreApproveForm.certEndDate = '';
                } else if (row.isLongTerm == '0') {
                    this.editPreApproveForm.isLongTerm = false;
                    this.editPreApproveForm.certEndDate = row.certEndDate;
                }
                this.editPreApproveModalVisible = true;
                this.id = row.id;
                let self = this;
                this.$nextTick(function () {
                    self.$refs.editcarUpload.resetimgurl();
                    self.$refs.editcarUpload.showCarImg(row.id);

                })
            },
            //保存
            storeInfo() {
                let transDate = '';
                let isLongTerm = '';
                if (this.addPreApproveForm.isLongTerm == false) {
                    transDate = utils.formatDate(this.addPreApproveForm.certEndDate, 'YYYY-MM-DD');
                    isLongTerm = '0'
                } else if (this.addPreApproveForm.isLongTerm == true) {
                    transDate = '9999-12-31'
                    isLongTerm = '1'
                }
                this.$refs.addPreApproveForm.validate((valid) => {
                    if (valid) {
                        if (this.modalType === 0) {
                            this.binary = '';
                            let datas = deepClone(this.addPreApproveForm);
                            datas.certEndDate = transDate;
                            datas.isLongTerm = isLongTerm;
                            datas.sellerPhone = this.sellerPhone;
                            datas.sellerRealName = this.sellerRealName;
                            datas.pcOrApp = "pc"
                            // 影像入参数
                            let param = this.queryParam(datas, 'add');
                            if (!param) {
                                this.$Message.warning("请上传身份证正反面");
                                return;
                            }
                            store(datas).then(res => {
                                if (res.code === "0000") {
                                    this.$Message.success("保存成功");
                                    this.refresh();
                                }
                            })
                        }
                    }
                });
            },
            // 查询影像上传入参数
            queryParam(datas, type) {
                let imgList = "";
                if (type == "add") {
                    imgList = this.$refs.addcarUpload.devierimglist();
                } else if (type == 'edit') {
                    imgList = this.$refs.editcarUpload.devierimglist();
                } else if (type == 'details') {
                    imgList = this.$refs.detailsCarUpload.devierimglist();
                }
                console.log(imgList, "imgList")
                if (imgList.length < 2) {
                    return false;
                }
                if (imgList.length > 0) {
                    let tempArr = [];
                    imgList.forEach((item, index) => {
                        tempArr.push(item.map)
                    })
                    datas.contractFileVos = tempArr;
                }
                return true
            },
            //提交
            submit() {
                let transDate = '';
                let isLongTerm = '';

                console.log(this.addPreApproveForm.isLongTerm, "this.addPreApproveForm.isLongTerm");
                console.log(this.editPreApproveForm.isLongTerm, "this.editPreApproveForm.isLongTerm");
                if (this.modalType === 0) {
                    this.$refs.addPreApproveForm.validate((valid) => {
                        if (valid) {
                            if (this.modalType === 0) {
                                if (this.refreshTime !== '') {
                                    this.destroyed();
                                    this.refreshTime = '';
                                }
                                if (this.addPreApproveForm.isLongTerm == false) {
                                    transDate = utils.formatDate(this.addPreApproveForm.certEndDate, 'YYYY-MM-DD');
                                    isLongTerm = '0'
                                } else if (this.addPreApproveForm.isLongTerm == true) {
                                    transDate = '9999-12-31';
                                    isLongTerm = '1'
                                }
                                this.binary = '';
                                let datas = deepClone(this.addPreApproveForm);
                                datas.certEndDate = transDate;
                                datas.isLongTerm = isLongTerm;
                                datas.sellerPhone = this.sellerPhone;
                                datas.sellerRealName = this.sellerRealName;
                                datas.pcOrApp = "pc"
                                // 影像入参数
                                let param = this.queryParam(datas, 'add');
                                if (!param) {
                                    this.$Message.warning("请上传身份证正反面");
                                    return;
                                }
                                save(datas).then(res => {
                                    if (res.code === "0000") {
                                        this.id = res.data.id;
                                        this.codeName = "刷新二维码";
                                        this.disabled = false;
                                        this.binary = res.data.code;
                                        this.refresh();
                                    }
                                })
                            }
                        }
                    });
                } else if (this.modalType === 1) {
                    this.$refs.editPreApproveForm.validate((valid) => {
                        if (valid) {
                            this.binary = '';
                            if (this.refreshTime !== '') {
                                this.destroyed();
                            }
                            if (this.editPreApproveForm.isLongTerm == false) {
                                transDate = utils.formatDate(this.editPreApproveForm.certEndDate, 'YYYY-MM-DD');
                                isLongTerm = '0'
                            } else if (this.editPreApproveForm.isLongTerm == true) {
                                transDate = '9999-12-31';
                                isLongTerm = '1'
                            }
                            let clone = deepClone(this.editPreApproveForm);
                            clone.channelId = this.channelId;
                            clone.sellerPhone = this.sellerPhone;
                            clone.userName = this.username;
                            clone.isLongTerm = isLongTerm;
                            clone.certEndDate = transDate;
                            clone.pcOrApp = "pc"
                            // 影像入参数
                            let param = this.queryParam(clone, 'edit');
                            if (!param) {
                                this.$Message.warning("请上传身份证正反面");
                                return;
                            }
                            // 修改预审批信息
                            edit(clone).then(res => {
                                if (res.code === "0000" && clone.applyStatus === '0') {
                                    this.codeName = "刷新二维码";
                                    this.binary = res.data.code;
                                    this.disabled = false;
                                    this.refresh();
                                } else {
                                    this.refresh();
                                    this.editPreApproveModalVisible = false;
                                }
                            })
                        }
                    });
                }
            },
            //MQ
            preApproveMessageSender(v) {
                let params = {
                    custName: v.custName,
                    certNo: v.certNo,
                    businessType: v.businessType,
                }
                preApproveMessageSender(params).then(res => {
                    if (res.code === '0000') {
                        this.$Message.success("提交成功")
                    }
                })
            },
            //删除（非物理删除）
            remove(v) {
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除 " + v.custName + " ?",
                    onOk: () => {
                        deletePreApprove(v).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success("删除成功");
                                this.refresh();
                            }
                        }).catch(() => {
                            this.refresh();
                        });
                    }
                });
            },
            // 通过角色设置新车、二手车权限
            setCurrentUserBusinessType(name) {
                var role = new Set();
                // var hasRoleCode = false;
                var roleCodeArr = new Set(['ROLE_RECORDED', 'ROLE_APPLY', 'ROLE_XCRECORDED', 'ROLE_XCAPPLY']);

                getUserInfo().then(res => {
                    if (res.code === "0000" && res.data.userExtInfo) {
                        let userExtInfo = res.data.userExtInfo;
                        let sysUser = res.data.sysUser;
                        this.sellerPhone = sysUser.phone;
                        this.sellerRealName = sysUser.userRealName;
                        this.username = sysUser.username;
                        if (userExtInfo.roles) {
                            let roles = userExtInfo.roles;
                            Array.isArray(roles) && roles.forEach(ele => {
                                let type = ele.roleTypeTemp;
                                if (roleCodeArr.has(ele.roleCode) && type && Array.isArray(type)) {
                                    type[0] ? role.add(type[0]) : '';
                                    type[1] ? role.add(type[1]) : '';
                                }
                                // if (roleCodeArr.has(ele.roleCode)) hasRoleCode = true;
                            });
                            let hasOldCar = role.has("oldCar");
                            let hasNewCar = role.has("newCar");
                            hasNewCar ? (this.isNewCarDisabled = false) : "";
                            hasOldCar ? (this.isOldCarDisabled = false) : "";
                        }
                    }
                });
            }
        }
        ,
        computed: {
            defines() {
                return [{id: "preApproveManageJS", fields: preApproveManageJS}];
            }
        }
        ,
    }
</script>
<style>

    .preApproveUpload .img_wp:first-child {
        margin-left: 120px;
    }

    .editPreApprove .img_wp:first-child {
        margin-left: 150px;
    }
</style>
<style lang="less" scoped>
    .preApproveFormOptionsForm {
        .ivu-date-picker,
        .ivu-select,
        .ivu-input,
        .ivu-checkbox-group,
        .ivu-input-wrapper {
            width: 100%;
            max-width: 250px;
        }
    }

    .uploadInfo > label {
        color: #333;
        display: block;
        position: absolute;
        width: 120px;
        text-align: right;
        padding-right: 12px;
    }

    .editPreApprove > label {
        width: 150px;
    }
</style>
<style lang="less" scoped>
    @import "../../assets/css/applyList.less";
</style>
